package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author youli.chen
 * @version v1.0
 * @description: 客户规则的子类型选项枚举
 * @date 2019/5/30 11:06
 * @since v1.0
 */
@Getter
public enum CustomerChildTypeEnum {

    // 所有客户统一设置
    CUSTOMER_CHILD_ZERO_STAR("enum.customerChildType.name.customer_child_zero_star", 0),
    // 根据客户状态设置
    CUSTOMER_CHILD_ONE_STAR("enum.customerChildType.name.customer_child_one_star", 1),
    // 根据客户重要程度设置
    CUSTOMER_CHILD_TWO_STAR("enum.customerChildType.name.customer_child_two_star", 2),
    // 根据标签设置
    CUSTOMER_CHILD_THREE_STAR("enum.customerChildType.name.customer_child_three_star", 3),
    // 非法类型
    UNKNOWN("enum.customerChildType.name.unknown", 404);

    private String name;
    private int code;

    CustomerChildTypeEnum(String name, int code) {
        this.name = name;
        this.code = code;
    }

    public static CustomerChildTypeEnum getChildTypeByCode(Integer code) {
        if (code == null) {
            return UNKNOWN;
        }
        for (CustomerChildTypeEnum type : CustomerChildTypeEnum.values()) {
            if (Objects.equals(type.getCode(), code)) {
                return type;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
